package com.gitee.dufafei.spark.core

import com.gitee.dufafei.spark.conf.SparkConfBuilder
import com.gitee.dufafei.spark.pattern.Logging
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

final class SparkSessionBuilder {

  private[this] val builder = SparkSession.builder()

  def setConf(conf: SparkConf): this.type = {
    System.err.println(s"${conf.toDebugString}")
    builder.config(conf)
    if (conf.contains(SparkConfBuilder.SPARK_HIVE_URIS)) builder.enableHiveSupport()
    this
  }

  def get(): SparkSession = builder.getOrCreate()
}

object SparkSessionBuilder extends Logging {

  def apply(): SparkSessionBuilder = new SparkSessionBuilder()
}